package com.bnq.control.desktop.popup;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.PopupWindow;

public class Popup extends PopupWindow {
	private Context mContext;
	protected View mViewContent;

	public Popup(Context context) {
		/*
		 * 调用不带参数的构造方法, mot-mt680、zte-u880e会崩溃 调用一个参数的构造方法, nexus-4 有全屏背景 所以,
		 * 调用带一个参数的构造方法, 设置背景为null.
		 */
		super(context);
		setBackgroundDrawable(null);
		mContext = context;
	}

	public Popup(Context context, int layoutRes) {
		this(context);
		mViewContent = LayoutInflater.from(context).inflate(layoutRes, null);
		setContentView(mViewContent);
		setWidth(LayoutParams.FILL_PARENT);
		setHeight(LayoutParams.FILL_PARENT);
		onInitView(mViewContent);
	}

	protected void onInitView(View rootView) {
	}

	/**
	 * Display the content view in a popup window.<br/>
	 * 相当于{@link #showAtLocation(token, int, int, int)}.
	 * 
	 * @param token
	 */
	public void show(View token) {
		showAtLocation(token, Gravity.TOP | Gravity.LEFT, 0, 0);
	}

	public Context getContext() {
		return mContext;
	}

	public View getRootView() {
		if (null != mViewContent) {
			return mViewContent;
		} else {
			return null;
		}
	}

}
